<?php
/**
 *显示home页面
 */
function home_build_page($page = 1) {
	$page = intval($page);
	if ($page <= 0) {
		$page = 1;
	}

	//获取数据
	$home_data = array();
	$home_data = get_site_data($home_data);
	include_once APP_PATH . '/post/model.php';

	$home_data['is_home'] = true;

	$home_data['post_list'] = post_model_get_list($page);

	$total_count = post_model_get_list_count_by_category_id();
	$num = 10;
	$page_url = '/home';
	$home_data['page_navigation'] = get_front_page_navigation($total_count, $page, $num, $page_url);

	//输出
	if ($home_data) {
		return home_build_html($home_data, $page);
	} else {
		return "";
	}

}
/**
 * 生成home页面
 */
function home_build_html($home_data = array(), $page = 1) {

	$build_path = HOME_HTML_PATH . $page . '.html';

	$home_file_path = ROOT_PATH . 'index.html';

	$build_path = filter_build_path($build_path);
	if (!$build_path) {
		return false;
	}
	$template = 'home.php';
	if (!empty($home_data['template'])) {
		$template = $home_data['template'];
	}
	$page_data = $home_data;
	$build_file_content = "";
	ob_start();
	require_once APP_VIEW . '/' . $template; //引入模版文件
	file_put_contents($build_path, ob_get_contents()); //生成静态文件
	if ($page == 1) {
		file_put_contents($home_file_path, ob_get_contents()); //生成首页静态文件
	}
	$build_file_content = ob_get_contents();
	ob_clean();
	return $build_file_content;
}